package com.mauroleon.promotail.common;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.mauroleon.promotail.domain.Usuario;

/**
 * Servlet Filter implementation class WhereeatFilter
 */
public class PromotailFilter implements Filter {

	/**
	 * Default constructor.
	 */

	public PromotailFilter() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {

		HttpServletRequest httpServletRequest = (HttpServletRequest) request;

		System.out.println("sss");
		HttpSession session = httpServletRequest.getSession();
		Usuario usuario = (Usuario) session.getAttribute("usuario");

		Cookie[] cookies = ((HttpServletRequest) request).getCookies();

		for (Cookie cookie : cookies) {
			System.out.println(cookie.getName());

			// cookie.setMaxAge(0);
			// response.addCookie(cookie);
		}
		chain.doFilter(request, response);

	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
